#include "TurnController.h"

#include <boost/bind.hpp>
#include "../domain/models/Player.h"
#include "../views/DependencyContainer.h"

using namespace Controllers;

TurnController::TurnController(Players::Player* current_player, Players::PlayersQueue players, 
	Cards::CardsCollection cards, Cards::CardSet searched_cards):
accusation_controller(current_player, cards, searched_cards), board_controller(current_player),
	deduction_controller(current_player, players, cards)
{
	connectEvent<void ()>(accusation_controller.accusationCorrectEvent, boost::bind(&TurnController::onAccusationCorrect, this));
	connectEvent<void ()>(accusation_controller.accusationIncorrectEvent, boost::bind(&TurnController::end, this));
	connectEvent<void ()>(accusation_controller.accusationNotPerformedEvent, boost::bind(&TurnController::performMove, this));

	connectEvent<void ()>(board_controller.movePerformedEvent, boost::bind(&TurnController::performDeduction, this));
	connectEvent<void ()>(deduction_controller.deductionPerformedEvent, boost::bind(&TurnController::end, this));
}

void TurnController::begin() 
{
	performAccusation();
}

void TurnController::performAccusation()
{
	accusation_controller.perform();
}

void TurnController::onAccusationCorrect()
{
	gameWinEvent();
}

void TurnController::performMove()
{
	board_controller.perform();
}

void TurnController::performDeduction()
{
	deduction_controller.perform();
}

void TurnController::end()
{
	turnEndEvent();
}

